<template>
    <div class="app-container">
        <el-row :gutter="20">
            <!--部门数据-->
            <!--用户数据-->
            <!-- <el-col :span="24" :xs="24">
                
                <el-row :gutter="10" class="mb8" v-if="isShowAdd">
                    <el-col :span="1.5">
              <el-button
                type="warning"
                plain
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['personnel:file:indexUser:export']"
                >导出</el-button
              >
            </el-col> -->
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" border :data="userList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column type="index" label="序号" width="50" align="center" />
            <el-table-column label="档案编号" width="150" align="center" prop="applyNo" />

            <el-table-column label="真实姓名" align="center" prop="nickName" />
            <el-table-column label="状态" align="center" prop="status">
                <template slot-scope="scope">
                    {{ scope.row.userTypeLabel}}
                </template>
            </el-table-column>
            <el-table-column label="部门" align="center" prop="deptName" :show-overflow-tooltip="true" />
            <el-table-column label="所在岗位" align="center" prop="postName" show-overflow-tooltip />
            <el-table-column label="入职时间" width="150" align="center" prop="joinDate" />
            <el-table-column label="申请离职日期" width="150" align="center" prop="leaveDate" />
            <!-- <el-table-column label="试用到期时间" width="150" align="center" prop="joinDate" /> -->
            <el-table-column label="操作" align="center" width="160" fixed="right" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" v-if="scope.row.userTypeLabel !='离职'" v-hasPermi="['company:certificate:info']"
                        @click="handleDetail(scope.row)">修改</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />
        </el-col>
        </el-row>
        <el-dialog :visible.sync="editCodeShow" title="修改工号" width="500px" append-to-body>
            <el-form ref="formEdit" :model="formEdit" :rules="rules" label-width="120px">
                <el-form-item label="新工号" prop="userName">
                    <el-input v-model="formEdit.userName" placeholder="请输入新工号" clearable :style="{ width: '100%' }">
                    </el-input>
                </el-form-item>
            </el-form>
            <template slot="footer">
                <el-button size="mini" @click="editCodeShow = false">取 消</el-button>
                <el-button size="mini" type="primary" @click="saveCode">确 定</el-button>
            </template>
        </el-dialog>
    </div>
</template>
  
<script>

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { optionselectPost } from "@/api/system/post.js";
import {
    applyList,
} from "@/api/application/depart.js";
//   import printStyle from "@/utils/print.js";

export default {
    name: "File",
    dicts: [
        "sys_user_sex",
        "sys_docbase_political",
        "sys_docbase_marital",
        "sys_docbase_professional",
        "sys_docbase_zzdj",
        "sys_docbase_user_type",
    ],
    components: { Treeselect },

    data() {
        return {
            isShowAdd: true,
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 用户表格数据
            userList: null,
            // 弹出层标题
            title: "维护项目资格证书",
            // 部门树选项
            deptOptions: undefined,
            // 是否显示弹出层
            open: false,
            // 部门名称
            deptName: undefined,
            // 默认密码
            initPassword: undefined,
            // 日期范围
            dateRange: [],
            JoinDate: [],
            // 岗位选项
            postOptions: [],
            // 角色选项
            roleOptions: [],
            // 表单参数
            form: { type: "1", certTypeId: undefined },
            rules: {
                userName: [
                    { required: true, message: "工号不能为空", trigger: "blur" },
                ],
                certTypeId: [
                    { required: true, message: "资格证书不能为空", trigger: "blur" },
                ],
            },
            defaultProps: {
                children: "children",
                label: "label",
            },

            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
            },
            openCertType: false,
            cretList: [],
            infos: [],
            printList: [],
            printLists: [],
            editCodeShow: false,
            formEdit: {},
        };
    },
    watch: {
        // 根据名称筛选部门树
        deptName(val) {
            this.$refs.tree.filter(val);
        },
    },
    created() {
        this.getList();
        this.optionselectPost();
    },
    methods: {
        saveCode() {
            this.$refs["formEdit"].validate((valid) => {
                if (valid) {
                    updateCode(this.formEdit).then((response) => {
                        this.$modal.msgSuccess("操作成功");
                        this.editCodeShow = false;
                        this.getList();
                    });
                }
            });
        },
        /** 查询用户列表 */
        getList() {
            this.loading = true;
            applyList(
                this.queryParams
            ).then((response) => {
                this.userList = response.rows;
                console.log(this.userList);
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                certTypeId: undefined,
                certTypeName: undefined,
                type: "1",
            };

            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = [];
            this.JoinDate = [];
            this.dateRange = [];
            this.resetForm("queryForm");
            this.queryParams.deptId = undefined;
            this.$refs.tree.setCurrentKey(null);
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.userDocBaseId);
            this.infos = selection;
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },
        optionselectPost() {
            optionselectPost().then((response) => {
                this.postOptions = response.data;
            });
        },
        handleDetail(row) {
            this.$router.push("../personnel/fileAdd?isEdit=true&id=" + row.userId);
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate((valid) => {
                if (valid) {
                    batchAddUserDocCertType(this.form).then((response) => {
                        this.$modal.msgSuccess("设置成功");
                        this.open = false;
                        this.getList();
                    });
                }
            });
        },
        handleExport() {
            this.download(
                "system/docBase/export",
                {
                    ...this.queryParams,
                    userDocBaseIds: this.ids.toString(),
                },
                `人员记录表_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}")}.xlsx`
            );
        },
    },
};
</script>
<style lang="scss" scoped>
.scaleFont {
    transform: scale(0.5);
    transform-origin: top left;
}

.table-page {
    width: 100%;
}

.wasd {
    td {
        padding: 1mm !important;
    }
}
</style>
  